import Vue from 'vue'
import Router from 'vue-router'
import Login from '@/views/Login'
import MyIndex from '@/views/my/index'
import HomeIndex from '@/views/home/index'
import MilkIndex from '@/views/milk/index'
import MilkDetail from '@/views/milk/detail'

import Regist from '@/views/Regist'

Vue.use(Router)

export default new Router({
  routes: [
    {
      // 首页
      path: '/',
      beforeEnter: (to, from, next) => {
        next('/home/index')
      }
    },
    {
      path: '/login',
      name: 'login',
      component: Login,
      // 前置路由守卫
      beforeEnter: (to, from, next) => {
        if (localStorage.getItem('token')) {
          console.log('存在token进入首页')
          next('/home/index')
        } else {
          next()
        }
      }
    },
    {
      path: '/regist',
      name: 'regist',
      component: Regist
    },
    {
      path: '/home/index',
      name: 'HomeIndex',
      component: HomeIndex
    },
    {
      path: '/my/index',
      name: 'MyIndex',
      component: MyIndex
    },
    {
      path: '/milk/index',
      name: 'MilkIndex',
      component: MilkIndex,
      // 前置路由守卫
      beforeEnter: (to, from, next) => {
        // console.log('进入存奶管理放行')
        next()
      }
    },
    {
      path: '/milk/detail',
      name: 'MilkDetail',
      component: MilkDetail
    }
  ]
})
